#pragma once

#include "../umlmodel_global.h"

#include <memory>
#include <vector>

#include "DirectedRelationship.h"
#include "NamedElement.h"

using std::make_shared;
using std::shared_ptr;
using std::vector;

namespace uml {
class Constraint;
class ExtensionPoint;
class UseCase;

/// <summary>
/// Extend
/// A relationship from an extending UseCase to an extended UseCase that specifies
/// how and when the behavior defined in the extending UseCase can be inserted into
/// the behavior defined in the extended UseCase.
/// </summary>
class UMLMODEL_EXPORT Extend : public NamedElement, public DirectedRelationship {

public: // Constructors and destructors
    explicit Extend(const QString& umlType="uml::Extend");

public: // JsonSerializable override
    void fromJson(const QJsonObject& json, QStringList& errorList) override;
    void toJson(QJsonObject& json) override;

public: // Properties
    /// <summary>
    /// condition getter
    /// References the condition that must hold when the first ExtensionPoint is reached
    /// for the extension to take place. If no constraint is associated with the Extend
    /// relationship, the extension is unconditional.
    /// </summary>
    shared_ptr<Constraint> condition() const;

    /// <summary>
    /// condition setter
    /// References the condition that must hold when the first ExtensionPoint is reached
    /// for the extension to take place. If no constraint is associated with the Extend
    /// relationship, the extension is unconditional.
    /// </summary>
    void setCondition(shared_ptr<Constraint> value);

    /// <summary>
    /// extendedCase getter
    /// The UseCase that is being extended.
    /// </summary>
    shared_ptr<UseCase> extendedCase() const;

    /// <summary>
    /// extendedCase setter
    /// The UseCase that is being extended.
    /// </summary>
    void setExtendedCase(shared_ptr<UseCase> value);

    /// <summary>
    /// extension getter
    /// The UseCase that represents the extension and owns the Extend relationship.
    /// </summary>
    shared_ptr<UseCase> extension() const;

    /// <summary>
    /// extension setter
    /// The UseCase that represents the extension and owns the Extend relationship.
    /// </summary>
    void setExtension(shared_ptr<UseCase> value);

    /// <summary>
    /// extensionLocations getter
    /// An ordered list of ExtensionPoints belonging to the extended UseCase, specifying
    /// where the respective behavioral fragments of the extending UseCase are to be
    /// inserted. The first fragment in the extending UseCase is associated with the
    /// first extension point in the list, the second fragment with the second point,
    /// and so on. Note that, in most practical cases, the extending UseCase has just a
    /// single behavior fragment, so that the list of ExtensionPoints is trivial.
    /// </summary>
    vector<shared_ptr<ExtensionPoint>>& extensionLocations();

private: // Fields
    /// <summary>
    /// condition
    /// References the condition that must hold when the first ExtensionPoint is reached
    /// for the extension to take place. If no constraint is associated with the Extend
    /// relationship, the extension is unconditional.
    /// </summary>
    shared_ptr<Constraint> condition_;

    /// <summary>
    /// extendedCase
    /// The UseCase that is being extended.
    /// </summary>
    shared_ptr<UseCase> extendedCase_;

    /// <summary>
    /// extension
    /// The UseCase that represents the extension and owns the Extend relationship.
    /// </summary>
    shared_ptr<UseCase> extension_;

    /// <summary>
    /// extensionLocations
    /// An ordered list of ExtensionPoints belonging to the extended UseCase, specifying
    /// where the respective behavioral fragments of the extending UseCase are to be
    /// inserted. The first fragment in the extending UseCase is associated with the
    /// first extension point in the list, the second fragment with the second point,
    /// and so on. Note that, in most practical cases, the extending UseCase has just a
    /// single behavior fragment, so that the list of ExtensionPoints is trivial.
    /// </summary>
    vector<shared_ptr<ExtensionPoint>> extensionLocations_;

};

} // namespace uml
